<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#address").change(function(){		
		$.ajax({
			type:"get",
			url:"auth_findByAddress.do",
			data:"address="+$("#address option:selected").val(),
			dataType:"json",
			beforeSend:function(xmlHttpRequest){ //ajax 방식으로 요청하기 전에 수행
				//alert("beforeSend");
				xmlHttpRequest.setRequestHeader("ajax","true");			
			},
			success:function(data){
				
				var table=$("#address option:selected").val()+"에 사는 인원<br><br>";
				table+="<table border='1' cellpadding='5'>";
				table+="<tr><td>아이디</td><td>이름</td></tr>";
				
				$.each(data,function(index, list){
					table+="<tr><td>"+list.ID+"</td><td>"+list.NAME+"</td></tr>";
				});
				table+="</table>";				
				$("#resultView").html(table);
			},
			error:function(xhr,textStatus,error){			
				if(xhr.status=="555"){
					alert("로그인하세요!");
					location.href="${initParam.root}loginView.do";
				}
			}
		});
	});
});
</script>
</head>
<body>
<h3>주소찾기 서비스</h3>
<form id="findForm">
<select id="address">
<c:forEach items="${requestScope.list }" var="data">
	<option value="${data }">${data }</option>
</c:forEach>
</select><hr>
<div id="resultView"></div>
</form>
</body>
</html>